<?php require("/export/www/transportation/includes/variables.php"); ?>
<html>
<head>
<style type="text/css">
<!--
* {
	font-family:Verdana, Arial, Helvetica, sans-serif;
}
.monthTitle {
	font-size: 12px;
	font-weight: bold;
	text-align: center;
}
.arrows {
	text-align: center;
}
.dayTitle {
	background-color:#000000;
	color:#FFFFFF;
	font-size: 10px;
	font-weight: bold;
	text-align: center;
}
.openText {
	color:#FF0000;
	font-weight:bold;
}
.previousMonth {
	font-size: 10px;
	color: #999999;
	text-align: center;
	border: 1px solid black;
	background-color:#FFFFFF;
}
.previousMonthHover {
	font-size: 10px;
	color: #999999;
	text-align: center;
	border: 1px solid black;
	background-color:#D9D9FF
}
.currentMonth {
	font-size: 10px;
	color: #000000;
	text-align: center;
	border: 1px solid black;
	background-image: url("http://transpo.uconn.edu/images/circle_back.png");
}
.currentMonthHover {
	font-size: 10px;
	color: #000000;
	text-align: center;
	border: 1px solid black;
	background-color:#D9D9FF
}
.nextMonth {
	font-size: 10px;
	color: #999999;
	text-align: center;
	border: 1px solid black;
	background-color:#FFFFFF;
}
.nextMonthHover {
	font-size: 10px;
	color: #999999;
	text-align: center;
	border: 1px solid black;
	background-color:#D9D9FF
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function popupDate(date,formattedDate) {
	if(!opener.closed) { //opener is still open.. update the form
		opener.document.getElementById("shiftDate").innerHTML = formattedDate + "<input type=hidden name=shiftDate value='" + date + "'>" + opener.document.getElementById("hiddenDiv").innerHTML;
		self.close();
	}
}
// -->
</script>
</head>
<body style="text-align:center; " onLoad="self.focus();">

<?php

function generateMonth() {
	switch (func_num_args()) {
		case 0:
			if(isset($_REQUEST['month'])) {
				$date = $_REQUEST['month'];
			} else {
				$date = date("Ym");
			}
			break;
		case 1:
			$date = func_get_arg(0);
			break;
	}
	$month			= substr($date,4,2);
	$year			= substr($date,0,4);
	$monthTitle		= date("F Y",mktime(0,0,0,$month,1,$year));
	$priorMonthLink	= date("Ym",mktime(0,0,0,$month-1,1,$year));
	$nextMonthLink  = date("Ym",mktime(0,0,0,$month+1,1,$year));
	$startCell		= date("w",mktime(0,0,0,$month,1,$year));
	
	//begin outputting data
?>

<table style="margin:auto; border:1px solid black; background-image:url('http://transpo.uconn.edu/images/calendar_backgd.png');" border="0" cellspacing="3" cellpadding="2">
  <tr>
    <td class="arrows"><a href="<?= $_SERVER['PHP_SELF'] . "?month=" . $priorMonthLink ?>"><?= displayIcon(ICON_BACK) ?></a></td>
    <td colspan="5" class="monthTitle"><?=$monthTitle?></td>
    <td class="arrows"><a href="<?= $_SERVER['PHP_SELF'] . "?month=" . $nextMonthLink ?>"><?= displayIcon(ICON_FORWARD) ?></a></td>
  </tr>
  <tr>
    <td class="dayTitle" width="25">S</td>
    <td class="dayTitle" width="25">M</td>
    <td class="dayTitle" width="25">T</td>
    <td class="dayTitle" width="25">W</td>
    <td class="dayTitle" width="25">T</td>
    <td class="dayTitle" width="25">F</td>
    <td class="dayTitle" width="25">S</td>
  </tr>
  <tr>
<?php
	//begin building cells
	//how many blank cells...
	$i = 0;
	while($i<$startCell) {
		print "    <td></td>\n";
		$i ++;
	}

	//start with the cells..
	$i = 1;
	while(mktime(0,0,0,$month,$i,$year) < mktime(0,0,0,$month+1,1,$year)) {
		if(date("w",mktime(0,0,0,$month,$i,$year)) == 0) 
			//we are on a new week, close the previous row and start a new one
			print "  </tr>\n  <tr>\n";
		
		//print the cell
		print "    <td class=\"currentMonth\" onmouseover=\"this.className='currentMonthHover'\" onmouseout=\"this.className='currentMonth'\" onClick=\"javascript:popupDate('" . date("Ymd",mktime(0,0,0,$month,$i,$year)) . "','" . date("l, F j, Y",mktime(0,0,0,$month,$i,$year)) . "');\">" . date("j",mktime(0,0,0,$month,$i,$year)) . "</td>\n";
		$i++;
	}
	
	//grab current weekday
	$i = date("w",mktime(0,0,0,$month+1,1,$year));
	while($i<=6) {
		print "    <td></td>\n";
		$i ++;
	}

	print "  </tr>
</table>";

}
generateMonth();
?>
</body>
</html>